using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.UI.VSIntegration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;

namespace Microsoft.SqlServer.Management.SqlManagerUI
{
	[LocalizedPropertyResources("Microsoft.SqlServer.Management.SqlManagerUI.GenScriptWizSR"), TypeConverter(typeof(LocalizableTypeConverter))]
	internal class GenWizOptionsBase : IDynamicVisible
	{
		public enum ScriptCompatabilityOptions
		{
			[DisplayNameKey("OnlyScript80CompatibleFeatures")]
			Script80Compat,
			[DisplayNameKey("OnlyScript90CompatibleFeatures")]
			Script90Compat,
			[DisplayNameKey("OnlyScript100CompatibleFeatures")]
			Script100Compat
		}

		public enum ScriptStatisticsOptions
		{
			[DisplayNameKey("ScriptStatisticsNone")]
			ScriptStatsNone,
			[DisplayNameKey("ScriptStatisticsDDL")]
			ScriptStatsDDL,
			[DisplayNameKey("ScriptStatisticsAll")]
			ScriptStatsAll
		}

		public enum TypeOfDataToScriptOptions
		{
			[DisplayNameKey("OptionSchemaAndData")]
			SchemaAndData,
			[DisplayNameKey("OptionDataOnly")]
			DataOnly,
			[DisplayNameKey("OptionSchemaOnly")]
			SchemaOnly
		}

		public enum BooleanTypeOptions
		{
			[DisplayNameKey("SchemaQualifyTrue")]
			True,
			[DisplayNameKey("SchemaQualifyFalse")]
			False
		}

		private GenWizOptionsBase.BooleanTypeOptions schemaQualify;

		private bool generateScriptForDependentObjects;

		private bool includeDescriptiveHeaders;

		private bool includeVarDecimal;

		private bool scriptExtendedProperties = true;

		private bool scriptUseDatabase;

		private bool scriptSQLLogins;

		private bool scriptObjectLevelPermissions;

		private bool scriptCreate = true;

		private bool scriptDrop;

		private GenWizOptionsBase.ScriptCompatabilityOptions compatMode;

		private bool scriptIndexes;

		private bool scriptFullTextIndexes;

		private bool scriptTriggers = true;

		private bool scriptPrimaryKeys = true;

		private bool scriptForeignKeys = true;

		private bool uniqueKeys = true;

		private bool scriptCheckConstraints = true;

		private bool ownerQualify = true;

		private bool includeIfNotExists = true;

		private bool collation;

		private bool continueScriptingOnError;

		private bool appendToFile;

		private bool scriptDefaults = true;

		private bool convertUDDTToBaseType;

		private bool scriptDriIncludeSystemNames;

		private bool scriptAnsiPadding;

		private GenWizOptionsBase.ScriptStatisticsOptions scriptStatistics;

		private GenWizOptionsBase.TypeOfDataToScriptOptions _typeOfDataToScript;

		private GenWizOptionsBase.BooleanTypeOptions _dropExistingObjects;

		private int sqlServerVersion;

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Generateconvertuddt"), DisplayNameKey("ScriptConvertUDDT"), Browsable(false)]
		public bool ConvertUDDTToBaseType
		{
			get
			{
				return this.convertUDDTToBaseType;
			}
			set
			{
				this.convertUDDTToBaseType = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Generateusedatabase"), DisplayNameKey("ScriptUseDatabase"), Browsable(false)]
		public bool ScriptUseDatabase
		{
			get
			{
				return this.scriptUseDatabase;
			}
			set
			{
				this.scriptUseDatabase = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Generatescriptfordatabaselogins"), DisplayNameKey("ScriptLogins"), Browsable(false)]
		public bool ScriptLogins
		{
			get
			{
				return this.scriptSQLLogins;
			}
			set
			{
				this.scriptSQLLogins = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("scriptCreateDescription"), DisplayNameKey("scriptCreate"), Browsable(false)]
		public bool ScriptCreate
		{
			get
			{
				return this.scriptCreate;
			}
			set
			{
				this.scriptCreate = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("scriptDropDescription"), DisplayNameKey("scriptDrop"), Browsable(false)]
		public bool ScriptDrop
		{
			get
			{
				return this.scriptDrop;
			}
			set
			{
				this.scriptDrop = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Generateobjectlevelpermissions"), DisplayNameKey("ScriptObjectLevelPermissions"), Browsable(false)]
		public bool ScriptObjectLevelPermissions
		{
			get
			{
				return this.scriptObjectLevelPermissions;
			}
			set
			{
				this.scriptObjectLevelPermissions = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Generatescriptfordependentobjectsofeachtablescripted"), DisplayNameKey("GenerateScriptForDependentObjects"), Browsable(false)]
		public bool GenerateScriptForDependentObjects
		{
			get
			{
				return this.generateScriptForDependentObjects;
			}
			set
			{
				this.generateScriptForDependentObjects = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Includedescriptiveheadersforeachtablescripted"), DisplayNameKey("IncludeDescriptiveHeaders"), Browsable(false)]
		public bool IncludeDescriptiveHeaders
		{
			get
			{
				return this.includeDescriptiveHeaders;
			}
			set
			{
				this.includeDescriptiveHeaders = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("IncludeVarDecimalDescription"), DisplayNameKey("IncludeVarDecimal"), Browsable(false)]
		public bool IncludeVarDecimal
		{
			get
			{
				return this.includeVarDecimal;
			}
			set
			{
				this.includeVarDecimal = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Continuescriptifanerroroccuredorotherwisestop"), DisplayNameKey("ContinueScriptingOnError"), Browsable(false)]
		public bool ContinueScriptingOnError
		{
			get
			{
				return this.continueScriptingOnError;
			}
			set
			{
				this.continueScriptingOnError = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Appendtofilethegeneratedscript"), DisplayNameKey("AppendToFile"), Browsable(false)]
		public bool AppendToFile
		{
			get
			{
				return this.appendToFile;
			}
			set
			{
				this.appendToFile = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Scriptextendedpropertiesforeachtablescripted"), DisplayNameKey("ScriptExtendedProperties"), Browsable(false)]
		public bool ScriptExtendedProperties
		{
			get
			{
				return this.scriptExtendedProperties;
			}
			set
			{
				this.scriptExtendedProperties = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("generatescriptstatistics"), DisplayNameKey("ScriptStatistics"), Browsable(false)]
		public GenWizOptionsBase.ScriptStatisticsOptions ScriptStatistics
		{
			get
			{
				return this.scriptStatistics;
			}
			set
			{
				this.scriptStatistics = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("generateDriIncludeSystemNames"), DisplayNameKey("ScriptDriIncludeSystemNames"), Browsable(false)]
		public bool ScriptDriIncludeSystemNames
		{
			get
			{
				return this.scriptDriIncludeSystemNames;
			}
			set
			{
				this.scriptDriIncludeSystemNames = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("generateAnsiPadding"), DisplayNameKey("ScriptAnsiPadding"), Browsable(false)]
		public bool ScriptAnsiPadding
		{
			get
			{
				return this.scriptAnsiPadding;
			}
			set
			{
				this.scriptAnsiPadding = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Scriptownerfortheobjects"), DisplayNameKey("ScriptOwner"), Browsable(false)]
		public bool OwnerQualify
		{
			get
			{
				return this.ownerQualify;
			}
			set
			{
				this.ownerQualify = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Scriptobjectswithifnotexistoption"), DisplayNameKey("IncludeIfNotExists"), Browsable(false)]
		public bool IncludeIfNotExists
		{
			get
			{
				return this.includeIfNotExists;
			}
			set
			{
				this.includeIfNotExists = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("Scriptobjectswithcollation"), DisplayNameKey("Collation"), Browsable(false)]
		public bool Collation
		{
			get
			{
				return this.collation;
			}
			set
			{
				this.collation = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("ScriptDefaults"), DisplayNameKey("Default"), Browsable(false)]
		public bool Default
		{
			get
			{
				return this.scriptDefaults;
			}
			set
			{
				this.scriptDefaults = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("CompatibleFeaturesDescription"), DisplayNameKey("CompatibleFeatures")]
		public GenWizOptionsBase.ScriptCompatabilityOptions ScriptCompatibilityOption
		{
			get
			{
				return this.compatMode;
			}
			set
			{
				this.compatMode = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scriptindexesforeachtablescripted"), DisplayNameKey("ScriptIndexes"), Browsable(false)]
		public bool ScriptIndexes
		{
			get
			{
				return this.scriptIndexes;
			}
			set
			{
				this.scriptIndexes = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scriptfulltextindexesforeachtablescripted"), DisplayNameKey("ScriptFullTextIndexes"), Browsable(false)]
		public bool ScriptFullTextIndexes
		{
			get
			{
				return this.scriptFullTextIndexes;
			}
			set
			{
				this.scriptFullTextIndexes = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scripttriggersforeachtablescripted"), DisplayNameKey("ScriptTriggers"), Browsable(false)]
		public bool ScriptTriggers
		{
			get
			{
				return this.scriptTriggers;
			}
			set
			{
				this.scriptTriggers = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scriptprimarykeysforeachtablescripted"), DisplayNameKey("ScriptPrimaryKeys"), Browsable(false)]
		public bool ScriptPrimaryKeys
		{
			get
			{
				return this.scriptPrimaryKeys;
			}
			set
			{
				this.scriptPrimaryKeys = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scriptuniqueskeysforeachtablescripted"), DisplayNameKey("ScriptUniqueKeys"), Browsable(false)]
		public bool UniqueKeys
		{
			get
			{
				return this.uniqueKeys;
			}
			set
			{
				this.uniqueKeys = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scriptforeignkeysforeachtablescripted"), DisplayNameKey("ScriptForeignKeys"), Browsable(false)]
		public bool ScriptForeignKeys
		{
			get
			{
				return this.scriptForeignKeys;
			}
			set
			{
				this.scriptForeignKeys = value;
			}
		}

		[DisplayCategoryKey("TableView"), DisplayDescriptionKey("Scriptcheckconstraintsforeachtablescripted"), DisplayNameKey("ScriptCheckConstraints"), Browsable(false)]
		public bool ScriptCheckConstraints
		{
			get
			{
				return this.scriptCheckConstraints;
			}
			set
			{
				this.scriptCheckConstraints = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("SchemaQualifyDesc"), DisplayNameKey("SchemaQualify")]
		public GenWizOptionsBase.BooleanTypeOptions SchemaQualify
		{
			get
			{
				return this.schemaQualify;
			}
			set
			{
				this.schemaQualify = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("OptionTypesOfDataDesc"), DisplayNameKey("OptionTypesOfData")]
		public GenWizOptionsBase.TypeOfDataToScriptOptions TypeOfDataToScript
		{
			get
			{
				return this._typeOfDataToScript;
			}
			set
			{
				this._typeOfDataToScript = value;
			}
		}

		[DisplayCategoryKey("General"), DisplayDescriptionKey("DropExistingObjectsDesc"), DisplayNameKey("DropExistingObjects")]
		public GenWizOptionsBase.BooleanTypeOptions DropExistingObjects
		{
			get
			{
				return this._dropExistingObjects;
			}
			set
			{
				this._dropExistingObjects = value;
			}
		}

		public GenWizOptionsBase(int version)
		{
			this.sqlServerVersion = version;
			if (this.sqlServerVersion == 8)
			{
				this.compatMode = GenWizOptionsBase.ScriptCompatabilityOptions.Script80Compat;
				return;
			}
			if (this.sqlServerVersion == 9)
			{
				this.compatMode = GenWizOptionsBase.ScriptCompatabilityOptions.Script90Compat;
				return;
			}
			this.compatMode = GenWizOptionsBase.ScriptCompatabilityOptions.Script100Compat;
		}

		public ICollection ConfigureVisibleEnumFields(ITypeDescriptorContext context, ArrayList values)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}
			if (context.PropertyDescriptor.PropertyType == typeof(GenWizOptionsBase.ScriptCompatabilityOptions))
			{
				int arg_2D_0 = this.sqlServerVersion;
			}
			return values;
		}

		public virtual void LoadOptionBase(GenWizOptionsBase optionBase)
		{
			this.TypeOfDataToScript = optionBase.TypeOfDataToScript;
			this.schemaQualify = optionBase.schemaQualify;
			this.compatMode = optionBase.compatMode;
			if (this.compatMode == GenWizOptionsBase.ScriptCompatabilityOptions.Script80Compat)
			{
				this.sqlServerVersion = 8;
			}
			else if (this.compatMode == GenWizOptionsBase.ScriptCompatabilityOptions.Script90Compat)
			{
				this.sqlServerVersion = 9;
			}
			else if (this.compatMode == GenWizOptionsBase.ScriptCompatabilityOptions.Script100Compat)
			{
				this.sqlServerVersion = 10;
			}
			this.DropExistingObjects = optionBase.DropExistingObjects;
		}

		public virtual void LoadShellScriptingOptions(IScriptingOptions scriptingOptions)
		{
			this.generateScriptForDependentObjects = scriptingOptions.ScriptDependentObjects;
			this.includeDescriptiveHeaders = scriptingOptions.IncludeHeaders;
			this.includeVarDecimal = scriptingOptions.IncludeVarDecimal;
			this.scriptExtendedProperties = scriptingOptions.ScriptExtendedProperties;
			this.scriptUseDatabase = scriptingOptions.ScriptUseDatabase;
			this.scriptObjectLevelPermissions = scriptingOptions.ScriptPermissions;
			if (scriptingOptions.TargetVersion.Contains("2000"))
			{
				this.compatMode = GenWizOptionsBase.ScriptCompatabilityOptions.Script80Compat;
			}
			else if (scriptingOptions.TargetVersion.Contains("2005"))
			{
				this.compatMode = GenWizOptionsBase.ScriptCompatabilityOptions.Script90Compat;
			}
			else if (scriptingOptions.TargetVersion.Contains("2008"))
			{
				this.compatMode = GenWizOptionsBase.ScriptCompatabilityOptions.Script100Compat;
			}
			this.scriptIndexes = scriptingOptions.ScriptIndexes;
			this.scriptFullTextIndexes = scriptingOptions.ScriptFullTextIndexes;
			this.scriptTriggers = scriptingOptions.ScriptTriggers;
			this.scriptPrimaryKeys = scriptingOptions.ScriptPrimaryKeys;
			this.scriptForeignKeys = scriptingOptions.ScriptForeignKeys;
			this.uniqueKeys = scriptingOptions.ScriptUniqueKeys;
			this.scriptCheckConstraints = scriptingOptions.ScriptCheckConstraints;
			this.ownerQualify = scriptingOptions.SchemaQualify;
			this.includeIfNotExists = scriptingOptions.IncludeIfNotExists;
			this.collation = scriptingOptions.IncludeCollation;
			this.scriptDefaults = scriptingOptions.ScriptDefaults;
			this.convertUDDTToBaseType = scriptingOptions.ConvertUddtToBaseType;
			this.scriptDriIncludeSystemNames = scriptingOptions.ScriptDriIncludeSystemNames;
			this.scriptAnsiPadding = scriptingOptions.GenerateAnsiPadding;
			if (scriptingOptions.ScriptStatistics)
			{
				this.scriptStatistics = GenWizOptionsBase.ScriptStatisticsOptions.ScriptStatsDDL;
			}
		}

		internal void AddOptionsDesc(TreeNode topNode)
		{
			TreeNode treeNode = topNode.Nodes.Add(GenScriptWizSR.GenScriptGeneralDescRoot);
			Dictionary<string, TreeNode> dictionary = new Dictionary<string, TreeNode>(2);
			TypeConverter converter = TypeDescriptor.GetConverter(this);
			foreach (PropertyDescriptor propertyDescriptor in converter.GetProperties(this))
			{
				string text = propertyDescriptor.GetValue(this).ToString();
				MemberInfo[] member = propertyDescriptor.PropertyType.GetMember(text);
				for (int i = 0; i < member.Length; i++)
				{
					MemberInfo element = member[i];
					Attribute[] customAttributes = Attribute.GetCustomAttributes(element);
					if (customAttributes.Length >= 1 && customAttributes[0] is DisplayNameKeyAttribute)
					{
						text = GenScriptWizSR.Keys.GetString(((DisplayNameKeyAttribute)customAttributes[0]).Key);
					}
				}
				string category = propertyDescriptor.Category;
				TreeNode treeNode2 = null;
				if (!dictionary.TryGetValue(category, out treeNode2))
				{
					treeNode2 = treeNode.Nodes.Add(category);
					dictionary[category] = treeNode2;
				}
				treeNode2.Nodes.Add(GenScriptWizSR.GenScriptGeneralOutputFormat(propertyDescriptor.DisplayName, text));
			}
		}
	}
}
